<template>
	<view class="xilu">
		<hx-navbar :config="config">
			<block slot="center">
				<view class="">我的</view>
			</block>
		</hx-navbar>
		<view class="page-foot">
			<Footer :identity="4" :footState="1"></Footer>
		</view>
		<!-- <view class="back" @click="toBack"> <image src="/static/返回.png" mode="" class="back-img"></image>  </view> -->
		<view class="container">
			<image v-if="web_url" :src="web_url+'/uniapp_image/xilu_mine_bg.png'" mode="aspectFill" class="xilu_mine_bg"></image>
			<template v-if="login_status">
				
				<view class="pr z2">
					<view class="pt20 pb40 plr40 flex-box">
						<image :src="info.xilufitness_urls.staff_logo_image || '../../static/images/avatar.png' "
							mode="aspectFill" class="xilu_head_img">
						</image>
						<view class="flex-grow-1 pl30">
							<view class="fs40 colf fw500 lh56">{{info.staff_name || ''}}</view>
							<view class="flex-box mt20" v-if="info.group_image">
								<image :src="info.group_image" mode="widthFix" class="ico160"></image>
							</view>
						</view>
					</view>
					
					
					<view class="flex-box">
						
						<view class="flex-grow-1 tc">
							<view class="col2 fs42 fw500 lh60">{{info.accountInfo.wait_course_money || 0}}</view>
							<view class="mt10 fs28 colf">待上课佣金</view>
						</view>
					</view>
					
					
					<view class="plr25 ptb40">
						<view class="xilu_vip_nav">
							<image v-if="web_url" :src="web_url+'/uniapp_image/xilu_profile_card.png'" mode="aspectFill"
								class="xilu_vip_nav_bg">
							</image>
							<view class="xilu_vip_nav_view plr30 flex-box">
								<view class="flex-grow-1" @tap="redirect_url('../my_staff_income/my_staff_income')">
									<view class="fs28 colf lh28">可提现金额（元）</view>
									<view class="fs30 mt20 colf lh50">¥<text
											class="fs50">{{info.accountInfo.account || 0.00}}</text></view>
									<view class="fs28 colf lh28 mt40">全部金额（元）</view>
									<view class="fs30 colf lh34 mt15">¥<text
											class="fs34">{{info.accountInfo.total_account || 0.00}}</text></view>
								</view>
								<view @tap="redirect_url('../staff_payouts/staff_payouts')" class="xilu_go">提现</view>
							</view>
						</view>
						<view class="xilu_box">
							<view class="fs36 fw500 colf lh36">其他功能</view>
							<view>
								<button @tap="redirect_url('../staff_performance_ranking/staff_performance_ranking')"
									class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/业绩.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>业绩排名</view>
								</button>
								<button @tap="redirect_url('../staff_opened_ranking/staff_opened_ranking')"
									class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/开店.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>开店排名</view>
								</button>
								<button @tap="redirect_url('../staff_area_ranking/staff_area_ranking')"
									class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/区域.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>区域排名</view>
								</button>
								<button @click="returnindex('../mine/mine')"
									class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/返回.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>退出</view>
								</button>
							<!-- 	<button @tap="redirect_url('../about_us/about_us?is_type=2')" class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/xilu_tool7.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>关于我们</view>
								</button>
								<button @tap="redirect_url('../help_center/help_center?is_type=9')" class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/xilu_tool8.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>帮助中心</view>
								</button> -->
								
							</view>
							<view class="mycode" @click="codeOpen">我的二维码</view>
						</view>
					</view>
				</view>

			</template>

			<template v-else>

				<view class="pr z2" @tap="doLogin()">
					<view class="pt20 pb40 plr40 flex-box">
						<image src="@/static/images/avatar.png" mode="aspectFill" class="xilu_head_img">
						</image>
						<view class="flex-grow-1 pl30">
							<view class="fs40 colf fw500 lh56">点击登录</view>
							<view class="flex-box mt20">
								<image src="@/static/images/xilu_label_low.png" mode="widthFix" class="ico160"></image>
							</view>
						</view>
					</view>
					
					<view class="plr25 ptb40">
						<view class="xilu_vip_nav">
							<image v-if="web_url" :src="web_url+'/uniapp_image/xilu_profile_card.png'" mode="aspectFill"
								class="xilu_vip_nav_bg">
							</image>
							<view class="xilu_vip_nav_view plr30 flex-box">
								<view class="flex-grow-1">
									<view class="fs28 colf lh28">可提现金额（元）</view>
									<view class="fs30 mt20 colf lh50">¥<text class="fs50">0</text></view>
									<view class="fs28 colf lh28 mt40">全部金额（元）</view>
									<view class="fs30 colf lh34 mt15">¥<text class="fs34">0</text></view>
								</view>
								<view class="xilu_go">提现</view>
							</view>
						</view>
						<view class="xilu_box">
							<view class="fs36 fw500 colf lh36">其他功能</view>
							<view>
								<button class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/xilu_tool7.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>关于我们</view>
								</button>
								<button class="xilu_tool_item tc" hover-class="none">
									<image src="@/static/images/xilu_tool8.png" mode="aspectFill"
										class="xilu_tool_item_cover">
									</image>
									<view>帮助中心</view>
								</button>
							</view>
						</view>
					</view>
				</view>
			</template>

		</view>
		<u-popup :show="showCode" mode="center" bgColor="transparent" @open="codeOpen" @close="codeClose"
			:safeAreaInsetBottom="false">
			<view class="xilu_code_popup pr pt40">
				<image @click="codeClose()" src="@/static/images/xilu_close.png" mode="aspectFill" class="xilu_close">
				</image>
		
				<image :src="code_info_url" mode="aspectFill" class="xilu_code"></image>
				<view class="tc fs34 colf lh40">出示员工二维码</view>
			</view>
		</u-popup>
		<u-authorize @onAuthCancel="onAuthCancel($event)" @onAuthConfirm="onAuthConfirm($event)"
			:popupStatus="auth_status" :isAuth="2"></u-authorize>
	</view>
</template>

<script>
	const app = getApp();
	const webConfig = require("@/util/config");
	export default {
		data() {
			return {
				config: {
					back: false,
					leftSlot: true,
					centerSlot: true,
					backgroundColor: [0, '#0F1011'],
					statusBarFontColor: ['#ffffff'],
					color: ['#ffffff']
				},
				code_info: null,
				showCode: false,
				web_url:'',
				login_status: false,
				auth_status: false,
				info: null,
				userInfo: null,
				code_info_url:''
			}
		},
		mounted() {
			
					
				this.$http({
					url:"/addons/xilufitness/shop/thali"
				}).then(res => {
					
				})
		},
		methods: {
			toBack() {
					this.$api.navigate('../mine/mine')
			},
			//显示核销二维码
			codeOpen() {
				let _this = this
				this.$http({
					url: "/addons/xilufitness/staff/getCodeUrl",
					data: {
						id: _this.info.id,

					},
					method: "get"
				}).then(res => {
					
					_this.code_info_url = res.data
				})
				// this.code_info_url = this.info.id
				this.code_info = this.info
				this.showCode = true
				
			},
			codeClose() {
				this.showCode = false
			},
			getVipStatusText(status) {
			  // 0=未开通|支付失败|未支付 1=未过期 2=已过期
			  switch(Number(status)) {
			    case 0: return '未开通';
			    case 1: return '使用中';
			    case 2: return '已过期';
			    default: return '--';
			  }
			},
			getVipStatusClass(status) {
			  switch(Number(status)) {
			    case 0: return 'status-unopen';
			    case 1: return 'status-active';
			    case 2: return 'status-expired';
			    default: return '';
			  }
			},
			returnindex(url) {
				uni.reLaunch({
				    url: url
				});
			},
			formatDate(time) {
			  if (!time) return '--';
			  const d = new Date(Number(time) * 1000);
			  return `${d.getFullYear()}-${(d.getMonth()+1).toString().padStart(2,'0')}-${d.getDate().toString().padStart(2,'0')}`;
			},
			to_shop_member_card(recharge_id) {
					
					let _this = this;
					this.$api.navigate('../shop_member/shop_member?recharge_id=' + recharge_id,function(res) {
						res.eventChannel.emit('memberCardData', {
							userInfo: _this.info,
							rechargeInfo: _this.userInfo
						});
					})
				
			},
			toStudentJob(id) {
				this.$api.navigate('../students_job/students_job?id=' + id)
			},
			//获取详情
			getInfos() {
				let _this = this;
				this.$http({
					url: '/addons/xilufitness/staff/getStaffInfo',
					method: 'get'
				}).then(res => {
					if (res.code == 1) {
						_this.info = res.data.info;
						_this.userInfo = res.data.userInfo;
					}
				}).catch(error => {
					console.log('coachInfoError', error);
				})
			},
			//点击登录
			doLogin() {
				this.auth_status = true;
			},
			//授权取消
			onAuthCancel(e) {
				this.login_status = false;
				this.auth_status = false;
				this.$api.toast('取消授权，可能会使部分服务不能用，或页面信息不完整')
			},
			//授权成功
			onAuthConfirm(e) {
				this.login_status = true;
				this.auth_status = false;
				this.getInfos();
			},
			//页面跳转
			redirect_url(url) {
				let _this = this;
				this.$api.navigate(url, function(res) {
					res.eventChannel.emit('userData', {
						userInfo: _this.userInfo,
						coachInfo: _this.info
					});
					res.eventChannel.emit('coachData', {
						coachInfo: _this.info
					});
					res.eventChannel.on('coachWithdraw', function(params) {
						_this.getInfos();
					});
				});
			}
		},
		onLoad() {
			this.web_url = webConfig.base_url || '';
			let token = this.$api.getCache('token');
			let _this = this;
			let staff = this.$api.getCache('is_staff') || 0;
			
			if (token) {
				this.login_status = true;
				this.getInfos();
			}
			uni.$on('coachCheckOrder',function(params){
				_this.getInfos();
			});
		}
	}
</script>

<style lang="scss" scoped>
	.mycode{
		background-color: #ff9800;
		color:#101010;
		border-radius: 16rpx;
		padding:20rpx;
		text-align: center;
		font-size: 32rpx;
		margin-top: 50rpx;
	}
	.back {
		width: 40rpx;
		height:40rpx;
		z-index: 1000;
		font-size: 35rpx;
		color: #fff;
		position:absolute;
		top:118rpx;
		left:40rpx;
	}
	.back-img {
		width: 100%;
		height:100%;
	}
	.vip-status {
	  margin-top: 14rpx;
	  font-size: 28rpx;
	  font-weight: bold;
	  padding: 4rpx 22rpx;
	  border-radius: 18rpx;
	  display: inline-block;
	}
	.status-unopen {
	  background: #fff3e0;
	  color: #ff9800;
	}
	.status-active {
	  background: #e8f5e9;
	  color: #43a047;
	}
	.status-expired {
	  background: #ffebee;
	  color: #e53935;
	}
	.xilu {
		position: relative;
		&_code_popup {
			width: 600rpx;
			background: #404243;
			border-radius: 20rpx;
			border: 1px solid #454545;
			padding: 40rpx 0 50rpx;
		}
		
		&_close {
			width: 30rpx;
			height: 30rpx;
			position: absolute;
			top: 45rpx;
			right: 47rpx;
		}
		
		&_code {
			width: 405rpx;
			height: 400rpx;
			display: block;
			margin: 40rpx auto;
		}
		&_mine_bg {
			width: 750rpx;
			height: 630rpx;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 1;
		}

		&_head_img {
			width: 130rpx;
			height: 130rpx;
			border: 5rpx solid rgba(255, 255, 255, 0.3);
			border-radius: 50%;
		}

		&_sq {
			width: 2rpx;
			height: 43rpx;
			background: #A8A8A8;
		}

		&_vip_nav {
			width: 700rpx;
			height: 251rpx;
			position: relative;
			margin-bottom: 20rpx;
			&_bg {
				width: 700rpx;
				height: 251rpx;
				position: relative;
				border-radius: 20rpx;
			}

			&_view {
				width: 700rpx;
				height: 251rpx;
				position: absolute;
				top: 0;
				left: 0;
			}
		}

		&_go {
			width: 150rpx;
			height: 70rpx;
			line-height: 70rpx;
			text-align: center;
			font-size: 30rpx;
			font-weight: 400;
			color: #FFFFFF;
			background: #D7A35F;
			border-radius: 40rpx;
		}

		&_box {
			width: 700rpx;
			padding: 30rpx 25rpx 55rpx;
			background: #D7A35F;
			border-radius: 20rpx;
			margin-top: 20rpx;
		}

		&_tool_item {
			margin-top: 50rpx;
			font-size: 26rpx;
			font-weight: 400;
			color: #fff;
			line-height: 26rpx;
			display: inline-block;
			vertical-align: top;
			margin-right: 78rpx;
			width: 104rpx;

			&_cover {
				width: 60rpx;
				height: 61rpx;
				display: block;
				margin-left: auto;
				margin-right: auto;
				margin-bottom: 20rpx;
			}

			&:nth-of-type(4n) {
				margin-right: 0;
			}
		}

		&_ad {
			width: 700rpx;
			height: 284rpx;
			display: block;
			margin-top: 20rpx;
		}
	}

	::v-deep.hx-navbar__content__main_center_txt {
		/* #ifdef MP */
		padding-left: 140rpx;
		/* #endif */
	}

	.ls10 {
		letter-spacing: 10rpx;
	}

	.tdu {
		text-decoration: underline;
	}

	.ico160 {
		width: 160rpx;
		height: 160rpx;
	}

	button {
		padding-left: 0;
		padding-right: 0;
		border-radius: 0;
	}
	
</style>